package com.su.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.su.tools.PageData;

import net.sf.json.JSONObject;

//import org.json.JSONObject;
/**
 * 会员-接口类
 */
@Controller
@RequestMapping(value = "/bg")
public class BgController extends BaseController {
	@Resource(name = "userService")
	private UserService userService;

	@Resource(name = "dictService")
	private DictService dictService;
	// @Autowired
	// HttpServletRequest request;
	// @Autowired
	// HttpServletResponse response;

	/**
	 * 根据用户名获取会员信息
	 * 
	 * @throws Exception
	 */
	@RequestMapping(value = "/{params}")
	@ResponseBody
	public Object getAppuserByUsernmae(@PathVariable String params, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		response.setHeader("Access-Control-Allow-Origin", "*");
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("params", params);
		JSONObject json = null;
		
		if (! pd.checkValue("orgCode")){
			pd.put("orgCode", "0");
		}
		if (params.startsWith("U1")) {
			json = userService.invoke(pd);
		} else if (params.startsWith("D1")) {
			json = dictService.invoke(pd);
		} else {
			json.put("code", "100");
			json.put("msg", "没有找到该业务代码");
			return json;
		}
		return json;
	}
}